
	<div class="panel panel-default">
		<div class="panel-heading">
			<h3 class="panel-title">用户管理</h3>
		</div>
		<div class="panel-body">
			<table class="user-list" data-page="<#if pageIndex??>${pageIndex}<#else>1</#if>" data-page-size="<#if pageSize??>${pageSize}<#else>20</#if>" data-count="<#if count??>${count}<#else>0</#if>">
				<tr class="title-row">
					<th style="display:none"></th>
					<th>用户代码</th>
					<th>用户名</th>
					<th>单位代码</th>
					<th>单位名称</th>
					<th>完整用户名</th>
				</tr>
				<#if data??> <#list data as user>
				<tr>
					<td style="display:none">${user.id}</td>
					<td>${user.uniqueCode}</td>
					<td>${user.name}</td>
					<td>${user.unitUniqueCode}</td>
					<td>${user.unitName}</td>
					<td>${user.fullName}</td>				
				</tr>
				</#list> </#if>				
			</table>
		</div>
		<div class="panel-footer">
		</div>
	</div>

<script src="${request.contextPath}/js/suredy-list.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		var listConfig = ({
			header : true,
			footer : true,
			search : false,
			checkbox : true,			
			paginate : function(page, size) {
				$.suredy.loadContent('user/list.do?page=' + page + '&size=' + size);
			},
			
			btns : [ {
				text :'新建',
				icon : 'icon-plus',
				style : 'btn-info',
				click : function() {
					$.suredy.showModal({
						size : 'lg',
						icon : 'icon-plus',
						title : '新建用户',
						showFoot : false,
						uri : 'user/create.do'
					});
				}
			}, {
				text :'修改',
				icon : 'icon-edit',
				style : 'btn-danger',
				click : function() {
					var checked = $.suredy.list.checked($('.user-list'));
					if (checked.length == 0 ) {
						alert('请选择需要修改的用户!');
						return;
					} else if (checked.length > 1) {
						alert('只能修改一个用户!');
						return;
					} else {
						var userId = $( $( $.suredy.list.checked($('.user-list'))[0]).find('td' )[1] ).html();
						var uri = 'user/edit.do?userId=' + userId;
						$.suredy.showModal({
							size : 'lg',
							icon : 'icon-edit',
							title : '修改用户',
							showFoot : false,
							uri : uri
						});
					}
				}
			},  {
				text : '删除',
				icon : 'icon-remove',
				style : 'btn-danger',
				click : function() {
					var checked = $.suredy.list.checked($('.user-list'));
					if (checked.length == 0 ) {
						alert('请选择需要删除的用户!');
						return;
					} else if (checked.length > 1) {
						alert('只能删除一个用户!');
						return;
					} else {
						var userId = $( $( $.suredy.list.checked($('.user-list'))[0]).find('td' )[1] ).html();
						var uri = 'user/delete.do?userId=' + userId;
						var msg = '是否确认删除用户？\n\n\
									提示：\n\
									该操作将会删除该用户及对应的权限配置及角色映射关系！\n\
									请谨慎操作！';
				
						if (!window.confirm(msg)) {
							return;
						}
						$.ajax({
							url : uri,
							type : 'POST',
							success : function(msg) {
								if (!msg) {
									alert('Unknown exception!');
								} else if (!msg.success) {
									alert("删除用户失败！\n\n" + msg.msg);
								} else {
									alert("删除用户成功！");
									$.suredy.loadContent('user/list.do');
								}
							},
							error : function(a, b, c) {
								alert('Server error! ' + b);
							}
						});

					} //end else
				} // end click function
			} ,  {
				text : '角色',
				icon : 'icon-magnet',
				style : 'btn-default',
				click : function() {
					var checked = $.suredy.list.checked($('.user-list'));
					if (checked.length == 0 ) {
						alert('请选择需要管理的用户!');
						return;
					} else if (checked.length > 1) {
						alert('只能管理一个用户!');
						return;
					} else {
						var userId = $( $( $.suredy.list.checked($('.user-list'))[0]).find('td' )[1] ).html();
						var uri = 'user/role.do?userId=' + userId;
						$.suredy.showModal({
							size : 'lg',
							icon : 'icon-magnet',
							title : '用户-角色映射',
							showFoot : false,
							uri : uri
						});
					}
				}
			} ,  {
				text : '权限',
				icon : 'icon-search',
				style : 'btn-default',
				click : function() {
					var checked = $.suredy.list.checked($('.user-list'));
					if (checked.length == 0 ) {
						alert('请选择需要管理的用户!');
						return;
					} else if (checked.length > 1) {
						alert('只能管理一个用户!');
						return;
					} else {
						var userId = $( $( $.suredy.list.checked($('.user-list'))[0]).find('td' )[1] ).html();
						var uri = 'user/permission.do?userId=' + userId;
						$.suredy.showModal({
							size : 'lg',
							icon : 'icon-search',
							title : '用户权限定义',
							showFoot : false,
							uri : uri
						});
					}			
				}
			}]
		});	
		
		$('.user-list').list(listConfig);	
		
	});
</script>	